package thread;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class SyncAPIDemo2 {
    public static void main(String[] args) {
        Set<Integer> c = Collections.synchronizedSet(new HashSet<>());
        new Thread(() -> {
            for (int i = 0; i < 1000; ++i) {
                c.add(i);
            }
        }).start();
        new Thread(() -> {
            for (int i = 0; i < 1000; ++i) {
                c.add(i);
            }
        }).start();
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
//            e.printStackTrace();
        }
        System.out.println(c.size());
        System.out.println(c);
    }
}
